﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////


#include "GnufDisplayAndPickFilterBoard.h"
#include "GnufExplorer.h"
#include "GnufModelViewBoard.h"
#include "GnufInfo.h"
#include "GnufQtPalletHeader.h"
#include "GnufQtToolbar.h"
#include "GnufQtTree.h"
#include "QtGnufExplorer.h"
#include <QtWidgets/QVBoxLayout>
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gfam;

//_____________________________________________________________________________
// QtGnufExplorer class implementation
//
QtGnufExplorer::QtGnufExplorer(GnufExplorer* GnufExplorer)
    : m_GnufExplorer(GnufExplorer)
    , m_modelView(gcmp::UniqueString::Find("ModelView"), GnufExplorer->modelViewBoard(), QtGnufToolbar::eTree)
    , m_displayFilter(gcmp::UniqueString::Find("DisplayFilter"), GnufExplorer->displayFilterBoard(), QtGnufToolbar::eTree)
    , m_displayFilterRule(gcmp::UniqueString::Find("DisplayFilterRule"), GnufExplorer->displayFilterBoard(), QtGnufToolbar::eNameValuePairs)
    , m_qtWorkingUnitSwitcher(nullptr)
{
    auto layout = NEW_AS_QT_LAYOUT(QVBoxLayout, this);
    layout->setSpacing(0);
    layout->setContentsMargins(0, 0, 0, 0);

    setLayout(layout);

    layout->addWidget(m_modelView.qtToolbar());
    layout->addWidget(m_displayFilterRule.qtToolbar());
    layout->addWidget(m_displayFilter.qtToolbar());
}

QtGnufExplorer::~QtGnufExplorer()
{}

void QtGnufExplorer::setCurrentTab(int index)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_modelView.qtToolbar(), L"m_modelView.qtToolbar()为空指针", L"paramodel", L"2024-02-20");
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_displayFilterRule.qtToolbar(), L"m_displayFilterRule.qtToolbar()为空指针", L"paramodel", L"2024-02-20");
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_displayFilter.qtToolbar(), L"m_displayFilter.qtToolbar()为空指针", L"paramodel", L"2024-02-20");

    if (0 == index) {
        m_modelView.qtToolbar()->show();
        m_displayFilterRule.qtToolbar()->hide();
        m_displayFilter.qtToolbar()->hide();
    }
    else if (1 == index) {
        m_modelView.qtToolbar()->hide();
        m_displayFilterRule.qtToolbar()->hide();
        if (true)
        {
            m_displayFilter.qtToolbar()->show();
        }
    }
}

void QtGnufExplorer::destroy()
{
    m_modelView.destroy();
    m_displayFilter.destroy();
    m_displayFilterRule.destroy();
    // Finally, delete me, later.
    deleteLater();
}

void QtGnufExplorer::refreshAppearance()
{
    m_modelView.refreshAppearance();
    m_displayFilter.refreshAppearance();
    m_displayFilterRule.refreshAppearance();
}
